﻿using System;
using BlazorProject.Common.Configuration;
using BlazorProject.Common.Helper;

namespace BlazorProject.Common
{
    public class AppSettings
    {
        /// <summary>
        /// 验证码Cookie名字
        /// </summary>
        public static string LoginVerifyCookieName
        {
            get
            {
                try
                {
                    return ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("LoginVerifyCookieName").Value;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    return "bruce_login_verify_cookie";
                }
            }
        }
        /// <summary>
        /// 验证码cookie名字
        /// </summary>
        public static string VerifyCodeSecret
        {
            get
            {
                try
                {
                    return ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("VerifyCodeSecret").Value;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    return "bruce#_verify*_7cookie%3secret@8";
                }
            }
        }
        /// <summary>
        /// cookie有效时长(秒)
        /// </summary>
        public static int CookieExpire
        {
            get
            {
                try
                {
                    string cookieExpire = ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("CookieExpire").Value;
                    return Convert.ToInt32(cookieExpire);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    return 7200;
                }
            }
        }
        /// <summary>
        /// 每日登录错误限制次数
        /// </summary>
        public static int LoginErrorLimitCount
        {
            get
            {
                try
                {
                    string cookieExpire = ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("LoginErrorLimitCount").Value;
                    return Convert.ToInt32(cookieExpire);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    return 5;
                }
            }
        }
        /// <summary>
        /// 文件服务器域名
        /// </summary>
        public static string FileDomain
        {
            get
            {
                try
                {
                    return ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("FileDomain").Value;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                    return "http://localhost";
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string OrdersDtlImportPath
        {
            get
            {
                var def = "\\Files\\Template\\OrdersDtlImport.xls";
                try
                {
                    string value = ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("OrdersDtlImportPath").Value;
                    def = string.IsNullOrWhiteSpace(value) ? def : value;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
                return def;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string OrdersDtlImportConfigXmlPath
        {
            get
            {
                var def = "\\Files\\Template\\OrdersDtlImportConfig.xml";
                try
                {
                    string value = ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("OrdersDtlImportConfigXmlPath").Value;
                    def = string.IsNullOrWhiteSpace(value) ? def : value;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
                return def;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string ImportExcelDirPath
        {
            get
            {
                var def = "\\Upload\\Excel";
                try
                {
                    string value = ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("ImportExcelDirPath").Value;
                    def = string.IsNullOrWhiteSpace(value) ? def : value;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
                return def;
            }
        }
		/// <summary>
        /// 平台主网站域名
        /// </summary>
        public static string PlatCompanyDomain
        {
            get
            {
                try
                {
                    return ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("PlatCompanyDomain").Value;
                }
                catch (Exception ex)
                {
                    return "http://192.168.0.211:7082";
                }
            }
        }

        public static string ClientDomain
        {
            get
            {
                try
                {
                    return ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("ClientDomain").Value;
                }
                catch
                {
                    return "http://192.168.0.211:7083";
                }
            }
        }
        
        /// <summary>
        /// 通用导出表格模版地址
        /// </summary>
        public static string OutputExcelTemplatePath
        {
            get
            {
                var def = "\\Files\\templates\\excel_output.xls";
                try
                {
                    string value = ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("OutputExcelTemplatePath").Value;
                    def = string.IsNullOrWhiteSpace(value) ? def : value;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
                return def;
            }
        }
        /// <summary>
        /// Task Url
        /// </summary>
        public static string ServerUrl
        {
            get
            {
                var def = "http://localhost:6078/job";
                try
                {
                    string value = ConfigurationService.GetConfiguration().GetSection("AppSettings").GetSection("ServerUrl").Value;
                    def = string.IsNullOrWhiteSpace(value) ? def : value;
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
                return def;
            }
        }

    }
}
